<template xmlns="http://www.w3.org/1999/html">
  <sea-dialog ref="dialog">
    <!--新建-->
    <smart-form ref="form_create" method="POST" url="/sys/dic/config/info"
                v-show="operation==='new'" :on-succeed="callback">
      <smart-form-layout require name="name" label="名称">
        <smart-text-view name="name" placeholder="名称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="label" label="标签">
        <smart-text-view name="label" placeholder="标签"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="value" label="值">
        <smart-text-view name="value" placeholder="值"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="description" label="描述">
        <smart-text-view name="description" placeholder="描述"></smart-text-view>
      </smart-form-layout>
    </smart-form>

    <!--更新-->
    <smart-form ref="form_create" method="POST" url="/sys/dic/config/info"
                v-show="operation==='new'" :on-succeed="callback">
      <smart-form-layout require name="id" label="ID" hidden>
        <smart-text-view name="id" placeholder="ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="name" label="名称">
        <smart-text-view name="name" placeholder="名称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="label" label="标签">
        <smart-text-view name="label" placeholder="标签"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="value" label="值">
        <smart-text-view name="value" placeholder="值"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="description" label="描述">
        <smart-text-view name="description" placeholder="描述"></smart-text-view>
      </smart-form-layout>
    </smart-form>
  </sea-dialog>
</template>

<script>

export default {
    components: {},
    props: {
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function}
    },
    data() {
        return {
            // 操作名称
            operation: undefined
            //end
        }
    },
    methods: {
        /**
         * 新增/编辑操作成功，关闭当前窗口
         *
         * @param ret 后台响应数据
         */
        callback: function (ret) {
            this.$layers.succeed('操作成功!');
            // 刷新表单列表
            this.onSucceed(ret);
            // 关闭弹窗
            this.$refs.panel.close();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'edit') {
                let dialog = {title: `更新`};
                this.$refs.dialog.open(dialog).then(() => {
                    this.$refs.modifyForm.val(row);
                });
            } else if (evt === 'new') {
                let dialog = {title: `新建`};
                this.$refs.dialog.open(dialog);
            } else if (evt === 'delete') {
                this.$layers.delete({
                    url: '/kettle/variable/info'
                    , params: {id: row.name}
                }).then((ret) => {
                    if (ret.code === 0) {
                        this.$layers.succeed();
                    }
                });
            }
        }
    }
}
</script>
